<?php
	include_once dirname(dirname(dirname(__FILE__))).'/inc/bootConfig.php';
	include_once '../checkLogin.php';
	
	if($_POST['linksubmit']){
		if(isset($_POST['old']) && is_array($_POST['old'])){
			foreach ($_POST['old'] as $k=>$v){
				$upd['l_name']=$v['name'];
				$upd['l_order']=$v["order"];
				$upd['l_url']=$v["url"];
				$upd['l_mark']=$v["mark"];
				$tablename = 'zjx_links';
				Module_Edit::update($tablename,$upd,'l_id='.$k);
			}
		}
		if(isset($_POST['delete']) && is_array($_POST['delete'])){
			$ids = implode(',', $_POST['delete']);
			Module_Edit::delete('zjx_links','l_id in ('.$ids.')');
		}
		if(isset($_POST['new']) && is_array($_POST)){
			foreach ($_POST['new'] as $v){
				$upd['l_name']=$v['name'];
				$upd['l_order']=$v["order"];
				$upd['l_url']=$v["url"];
				$upd['l_mark']=$v["mark"];
				$upd['l_time']=date('Y-m-d H:i:s');
				$upd['l_user']=$_SESSION['username'];
				$tablename = 'zjx_links';
				Module_Edit::insert($tablename,$upd);
			}
		}
		$dir = "../../zjx/Runtime/Cache/selectModel/";
		Cache_Filecache::delFileCache($dir);
	}
	
	$alllinks = Module_Select::getAllLinks();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>编辑模块</title>
<link rel="stylesheet" type='text/css' href='../Public/static/css/admincp/admincp.css'>
</head>
<body>
<div id="cpcontainer" class="container">
<div class="itemtitle"><h3>友情链接</h3></div>
<table id="tips" class="tb tb2 ">
	<tbody>
		<tr>
			<th class="partition">技巧提示</th>
		</tr>
		<tr>
			<td class="tipsblock">
			<ul id="tipslis">
				<li>说明文字只显示在鼠标移动事件。</li>
				<li>首页的友情链接只显示10个，请作好处理。</li>
			</ul>
			</td>
		</tr>
	</tbody>
</table>
<form id="cpform" action="" method="post">
<table class="tb tb2 ">
	<tbody>
		<tr class="header">
			<th width="30px">删除</th>
			<th width="60px">显示顺序</th>
			<th width="150px">站点名称</th>
			<th width="200px">站点 URL</th>
			<th width="300px">文字说明(可选)</th>
		</tr>
	<?php 
		if(is_array($alllinks) && count($alllinks)>0){
			foreach ($alllinks as $v){
	?>
		<tr class="hover">
			<td class="td25"><input type="checkbox" value="<?php echo $v['l_id']?>" name="delete[]"
				class="checkbox"></td>
			<td class="td28"><input type="text" size="3" value="<?php echo $v['l_order']?>"
				name="old[<?php echo $v['l_id']?>][order]" class="txt"></td>
			<td><input type="text" size="25" value="<?php echo $v['l_name']?>" name="old[<?php echo $v['l_id']?>][name]" class=" "></td>
			<td><input type="text" size="30" value="<?php echo $v['l_url']?>"
				name="old[<?php echo $v['l_id']?>][url]" class=" "></td>
			<td class="td26"><input type="text" size="30"
				value="<?php echo $v['l_mark']?>" name="old[<?php echo $v['l_id']?>][mark]" class="txt"></td>
		</tr>
	<?php 
			}
		}
	?>
		<tr>
			<td></td>
			<td colspan="10">
			<div><a class="addtr" href="###">添加友情链接</a></div>
			</td>
		</tr>
		<tr>
			<td class="td25"></td>
			<td colspan="15">
			<div class="fixsel"><input type="submit" value="提交"
				title="按 Enter 键可随时提交你的修改" name="linksubmit" id="submit_linksubmit"
				class="btn"></div>
			</td>
		</tr>
	</tbody>
</table>
</form>

</div>
</body>
</html>
<script src="../Public/static/js/jquery.js"></script>
<script type="text/javascript">
var i=0
$('a.addtr').click(function(){
	i++
	$(this).parents('tr').before('<tr><td colspan="1" class="td25"></td><td colspan="1" class="td28"><input type="text" size="3" name="new['+i+'][order]"></td><td colspan="1"><input type="text" size="25" name="new['+i+'][name]"></td><td colspan="1"><input type="text" size="30" name="new['+i+'][url]" ></td><td colspan="1" class="td26"><input type="text" size="30" name="new['+i+'][mark]" class="txt"></td></tr>')
})
</script>